package org.easymis.crm.modules.crm.controller;

import java.util.List;

import org.easymis.commons.web.BaseController;
import org.easymis.commons.web.utils.Page;
import org.easymis.commons.web.utils.R;
import org.easymis.crm.config.SystemConstant;
import org.easymis.crm.modules.crm.entitys.mybatis.dto.CrmLeads;
import org.easymis.crm.modules.crm.service.CrmLeadsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "线索管理")
@Controller
public class CrmLeadsController extends BaseController{
	@Autowired
	private CrmLeadsService service;
	@ApiOperation(value = "线索管理列表页面", notes = "", produces = MediaType.TEXT_HTML_VALUE)
	@RequestMapping(value = { "/leads/index.html" }, method = { RequestMethod.GET, RequestMethod.POST })
	public String dashboards(ModelMap map) {

		return "/crm/leads/index";
	}
	
	@ApiOperation(value = "线索管理列表页面", notes = "", produces = MediaType.TEXT_HTML_VALUE)
	@RequestMapping(value = { "/leads/forward/list.html" }, method = { RequestMethod.GET, RequestMethod.POST })
	public String forwardList(ModelMap map, Page page) {
		return "/crm/leads/list";
	}
	@ApiOperation(value = "线索管理列表JSON数据", notes = "", produces = MediaType.TEXT_HTML_VALUE)
	@RequestMapping(value = { "/leads/list.json" }, method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public R forwardListJson(ModelMap map, Page page) {
		PageHelper.startPage(page.getCurPage(), page.getPageSize());
		List<CrmLeads> leadsList = service.getList(new CrmLeads());
		PageInfo<CrmLeads> p = new PageInfo<CrmLeads>(leadsList);
		return new R().put("page", p);
	}
	@ApiOperation(value = "跳转添加线索", notes = "", produces = MediaType.TEXT_HTML_VALUE)
	@RequestMapping(value = { "/leads/forward/add.html" }, method = { RequestMethod.GET, RequestMethod.POST })
	public String forwardAdd(ModelMap map, Page page) {
		return "/crm/leads/add";
	}
	@ApiOperation(value = "添加线索", notes = "", produces = MediaType.TEXT_HTML_VALUE)
	@RequestMapping(value = { "/leads/save.do" }, method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public R save(ModelMap map, CrmLeads bean) {
		service.save(bean);
		return new R().ok();
	}
	@ApiOperation(value = "线索列表", notes = "", produces = MediaType.TEXT_HTML_VALUE)
	@RequestMapping(value = { "/api/leads.json" }, method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public R apiDashboard(ModelMap map, Page page) {
		PageHelper.startPage(page.getCurPage(), page.getPageSize());
		List<CrmLeads> dashboardList = service.getList(new CrmLeads());
		PageInfo<CrmLeads> p = new PageInfo<CrmLeads>(dashboardList);
		return new R().put("page", p);
	}

	@ApiOperation(value = "线索详情", notes = "", produces = MediaType.TEXT_HTML_VALUE)
	@RequestMapping(value = { "/leads/{leadsid}.json" }, method = { RequestMethod.GET, RequestMethod.POST })
	public R view(@PathVariable("leadsId") String leadsId, ModelMap map) {
		return new R().ok();
	}

	@ApiOperation(value = "数据看板详情页面", notes = "", produces = MediaType.TEXT_HTML_VALUE)
	@RequestMapping(value = { "/leads/delete/{leadsId}" }, method = { RequestMethod.GET, RequestMethod.POST })
	public R delete(@PathVariable("leadsId") String leadsId, ModelMap map) {
		return new R().ok();
	}

	@ApiOperation(value = "公开线索详情页面", notes = "", produces = MediaType.TEXT_HTML_VALUE)
	@RequestMapping(value = { "/public/leads/{leadsId}.html" }, method = { RequestMethod.GET, RequestMethod.POST })
	public String publicDashboard(@PathVariable("leadsId") String leadsId, ModelMap map) {
		map.put("icp", SystemConstant.getICP());
		map.put("systemname", SystemConstant.getSystemName());
		map.put("systemdomain", SystemConstant.getSystemdomain());
		return "/main/leads/view";
	}
	@ApiOperation(value = "公开线索详情数据", notes = "", produces = MediaType.TEXT_HTML_VALUE)
	@RequestMapping(value = { "/public/leads/{leadsId}.json" }, method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public R publicDashboardJson(@PathVariable("leadsId") String leadsId, ModelMap map) {
		map.put("icp", SystemConstant.getICP());
		map.put("systemname", SystemConstant.getSystemName());
		map.put("systemdomain", SystemConstant.getSystemdomain());
		return new R().put("dashboard", service.findById(leadsId));
	}
}
